package com.longcai.piaojia.conn;

import android.widget.ListView;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/23.
 */
@HttpInlet(Conn.ORDER_INDEX)
public class MyOrderListGet extends BaseAsyGet<MyOrderListGet.MyOrderListEntity> {

    public String user_id;
    public int status, page;

    public MyOrderListGet(AsyCallBack<MyOrderListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected MyOrderListEntity parser(JSONObject object) throws Exception {

        if(object.optInt("code")==200){

            JSONObject jsonObject = object.optJSONObject("data");

            MyOrderListEntity myOrderListEntity = new MyOrderListEntity();
            myOrderListEntity.total = jsonObject.optInt("total");
            myOrderListEntity.per_page = jsonObject.optInt("per_page");
            myOrderListEntity.current_page = jsonObject.optInt("current_page");

            JSONArray jsonArray = jsonObject.optJSONArray("data");

            for(int i=0;i<jsonArray.length();i++){

                JSONObject jsonObject_item = jsonArray.optJSONObject(i);
                MyOrderEntity myOrderEntity = new MyOrderEntity();
                myOrderEntity.show_id = jsonObject_item.optString("show_id");
                myOrderEntity.order_number = jsonObject_item.optString("order_number");
                myOrderEntity.discount_price = jsonObject_item.optString("discount_price");
                myOrderEntity.title = jsonObject_item.optString("title");
                myOrderEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject_item.optString("picurl");
                myOrderEntity.place = jsonObject_item.optString("place");
                myOrderEntity.posttime = jsonObject_item.optString("posttime");

                myOrderListEntity.data.add(myOrderEntity);

            }

            return myOrderListEntity;

        }

        TOAST = object.optString("message");

        return null;
    }

    public static class MyOrderListEntity{

        public int total, per_page, current_page;
        public List<MyOrderEntity> data = new ArrayList<>();

    }

    public static class MyOrderEntity{

        public String order_number, title, posttime, discount_price, picurl, show_id, place;

    }

}
